package ModelLayer;
import java.util.ArrayList;
import java.util.Arrays;

/**
 * Vestbjerg project
 * @GroupB2 (UCN - Computer Science DMAJ0914) 
 */

public class CustomerContainer
{
    //instance variables
    private static CustomerContainer instance;
    private ArrayList<Customer> customerList;
    /**
     * Constructor for objects of class CustomerContainer
     */
    private CustomerContainer()
    {
        customerList = new ArrayList<Customer>();
    }
    
    public static CustomerContainer getInstance() 
    {
        if(instance == null) 
        {
            instance = new CustomerContainer();
        }
        return instance;
    }
    
    public void addCustomer(Customer customer) 
    {
        customerList.add(customer);
    }
    
    public Customer findCustomer(String id) 
    {
        Customer returnCustomer = null;
        for(Customer customer : customerList) 
        {
            
            if(id.equals(customer.getId())) 
            {
                returnCustomer = customer;
            }
        }
        return returnCustomer;
    }
    
    public void deleteCustomer(Customer customer) 
    {
        if(customerList.contains(customer)) 
        {
            customerList.remove(customer);
        }
    }
    
    public ArrayList<Customer> getCustomerList()
    {
        return customerList;
    }
    
    public ArrayList<String> customerSort()
    {
       ArrayList<String> sortedCustomerList = new ArrayList<String>();
       IFPerson[] customerArr = new IFPerson[customerList.size()];
       
       customerList.toArray(customerArr);
       Arrays.sort(customerArr);
       
       for(IFPerson customer : customerArr)
       {
            sortedCustomerList.add(customer.getId());
       }
       
       return sortedCustomerList;
    }
    
}